<?php
require_once("../inc/function.php");

function GetContactKeywords()
{
        $conn = GetConnection();
        return $conn->query('SELECT * FROM Contact_keywords');
}

function GetContactKeyword($id)
{
        $conn = GetConnection();
		if($id==NULL)
			die("Keyword couldn't be found with provided id or id is invalid. Please enter another id.");
        $sql = "SELECT * FROM Contact_keywords WHERE id=$id";
        $results = $conn->query($sql);        
        $row = $results->fetch_assoc();
        $conn->close();
        return $row;
}

function SaveContactKeyword($row)
{
		$conn = GetConnection();
		$id = $row['id'];
		$method = strip_tags($row['name']);
		if(strlen($method)>0)
		{
			   $conn->query("UPDATE `Contact_keywords` "
			   . "SET  Method = '$method' "
			   . "WHERE  id ='$id'");        
		}
		else 
		{
			header("Location: http://cs.newpaltz.edu/~N01852322/Final/ContactKeywords/edit.php?id=".$id."");
		}		  
        $conn->close();     	
}

function DeleteContactKeyword($id)
{
	$conn = GetConnection();
	$results = $conn->query("DELETE FROM Contact_keywords WHERE id=$id");
	header('Location: http://cs.newpaltz.edu/~N01852322/Final/ContactKeywords/');
}

function NewContactKeyword($row)
{
	$contact_keyword = strip_tags($row['contact_keyword']);
	if(strlen($contact_keyword)>0)	
	{
		$conn = GetConnection();
		$conn->query("INSERT INTO Contact_keywords Values(NULL, '$contact_keyword')");
		$conn->close();
	}
	else 
	{
		die("You need to enter a contact keyword value");	
	}
}